#include "IOTController.hpp"
SocketServer * server = SocketServer::getInstance();
int data_tem[4];
mutex mutex_data;
void init_network()
{
	server->onDisconnect = [](HSocket it) {
		pri<HSocket>("Disconnect", it);
		//UserList->erase(it);
	};
	server->onError = [](ErrorCode ecode) {
		pri<int>("Error", ecode);
	};
	server->onNewConnection = [](HSocket it) {
		pri<HSocket>("NewConnect", it);
	};
	server->onRecv = [](HSocket it, shared_ptr<DataStream> dm) {
		mutex_data.lock();
		for (int i = 0; i < 4; ++i) {
			dm->DoObj<int>(data_tem[i]);
		}
		cout << "[Humidity]" << data_tem[0] << "." << data_tem[1] << "	[Tempreture]" << data_tem[2] << "." << data_tem[3] << endl;
		mutex_data.unlock();
	};

	server->onStart = [](const char * ip) {
		pri<string>("IP", ip);
	};
	server->startServer(8331, true, false);
}
